import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import HttpApi from 'i18next-http-backend';
import translationEN from './locales/en/translation.json';
import translationZH from './locales/zh/translation.json';

i18n
  .use(HttpApi)
  .use(initReactI18next)
  .init({
    fallbackLng: 'en',
    debug: true,
    interpolation: {
      escapeValue: false,
    },
    resources: {
      en: {
        translation: translationEN
      },
      zh: {
        translation: translationZH
      }
    },
    ns: ['translation'], 
    defaultNS: 'translation', 
  }, (err, t) => {
    if (err) {
      console.error('i18n 初始化失败:', err);
    } else {
      console.log('i18n 初始化成功');
    }
  });

export default i18n;